import { inject } from "vue";
let allData = null;
export default () => {
    let chartInstance = null;
    //初始化
    const initChart = (app_ref, initOption) => {
        //挂载chart
        chartInstance = inject("chart").init(app_ref);
        chartInstance.setOption(initOption);
    };
    //更新
    const getData = async (url, fun) => {
        // 获取数据
        const { data: ret } = await inject("http").get(url);
        fun();
        allData = ret
        console.log(allData);
        upDateChart(allData);
    };
    //更新数据
    const upDateChart = (dataOption) => {
        chartInstance.setOption(dataOption);
    };
   //更新数据
    const screenAdapt = (adaptOption) => {
        chartInstance.setOption(adaptOption);
        chartInstance.resize();
    };


    return {
        initChart,
        getData,
        upDateChart,
        screenAdapt,
        allData
    }
};